﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

using System.Runtime.Serialization;

namespace WCFMINERP.Contracts.DataContracts
{
    [DataContract]
    public class TransferFileInfo
    {

        //文件名
        [DataMember]
        public string Name { get; set; }

        //文件大小
        [DataMember]
        public long Length { get; set; }

        //文件的偏移量
        [DataMember]
        public long Offset { get; set; }

        //传递的字节数
        [DataMember]
        public byte[] Data { get; set; }

        //创建时间
        [DataMember]
        public DateTime CreateTime { get; set; }
        //文件状态0等待1上传中2完成3暂停4删除
        [DataMember]
        public int Status { get; set; }
        [DataMember]
        public string ShopName { get; set; }
        /// <summary>
        /// 客户端存放文件的目录
        /// </summary>
        [DataMember]
        public string ShopTempPath { get; set; }
        /// <summary>
        /// 客户端所在的机器名字
        /// </summary>
        [DataMember]
        public string MachineName { get; set; }


        [DataMember]
        public decimal LastGuage { set; get; }//上一次进度
        [DataMember]

        public DateTime LastTime { get; set; }//上一次更改时间
        [DataMember]
        public DateTime SaveTime { get; set; }//上一次更改时间

        public string Speed
        {
            get
            {
                if (Offset == 0 || SaveTime < Convert.ToDateTime("2000-01-01"))
                {
                    return "0k/s";
                }
                if (Convert.ToDecimal((SaveTime - LastTime).TotalSeconds) == 0)
                {
                    return "0k/s";
                }
                else
                {
                    decimal Sd = (Offset - LastGuage) / Convert.ToDecimal((SaveTime - LastTime).TotalSeconds);
                    if (Sd <= 1024)
                    {
                        return Sd.ToString("0.00") + "B/s";
                    }
                    else if (Sd >= 1024 && Sd < 1048576)
                    {
                        return (Sd / 1024).ToString("0.00") + "KB/s";
                    }
                    else if (Sd >= 1048576)
                    {
                        return (Sd / 1024 / 1024).ToString("0.00") + "MB/s";
                    }
                    else
                    {
                        return (Sd / 1024 / 1024).ToString("0.00") + "KB/s";
                    }

                }
            }
            set { ;}
        }//速度
        //进度
        public string GuagaPresent
        {
            get
            {
                if (Length == 0)
                {
                    return "0";
                }
                else
                {
                    return ((decimal)Offset / (decimal)Length * 100).ToString("0.00") + "%";
                }
            }




        }
        [DataMember]
        public int ShopID { get; set; }//商户ID
        [DataMember]
        public string Remark { get; set; }//备注
        [DataMember]
        public string FileDisLength
        {
            get
            { return ((decimal)Length / 1024 / 1024).ToString("0.00") + "MB"; }
            set { ;}
            
        }//备注

    }
}
